<template>

	<view>
		<u-navbar :is-back="true" :border-bottom="false" title="执业培训" height="46" title-color="#333" :title-bold="true"
		 :title-size="36">
			<view class="navbar_wap">
				<view class="navbar-right">
					<u-icon name="search" color="#C40200" size="45" class="search_logo" @click="goSearch"></u-icon>
					<u-icon name="scan" color="#C40200" size="45" @click="scancode"></u-icon>
				</view>
			</view>
		</u-navbar>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper ref="uTabs" :list="pralist" :current="current" @change="tabsChange" :is-scroll="false" swiperWidth="750"
				 bar-width="92" :active-item-style="{marginBottom:'10rpx'}" active-color="#c40200" :bar-style="{backgroundColor:'#c40200',height:'5rpx',borderRadius: '5rpx'}"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item class="swiper-item" v-for="(item,index) in pralist" :key="index">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
						<view class="page-box">
							<view class="services_box">
								<view class="atlas_img">
									<image src="../../../static/index/practice_nav.png" mode="widthFix"></image>
								</view>
								<home-notice :notice="bkzllist" style="margin-bottom: 18rpx;" @goDetail="goDetail"></home-notice>
							</view>
							<pra-swiper :navlist="navlist"></pra-swiper>
							<view class="pra_list_box">
								<view class="">
									<image src="../../../static/atlas/zthz.png" mode="widthFix"></image>
								</view>
								<view class="">
									<image src="../../../static/atlas/hldzjc.png" mode="widthFix"></image>
								</view>
							</view>
							<practice-data :list="recomlist"></practice-data>
							<u-gap height="20" bg-color="#F7F7F7"></u-gap>
							<practice-list :bkzllist="bkzllist"></practice-list>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>

	</view>
</template>

<script>
	import HomeNotice from "../../../components/common/HomeNotice.vue"
	import PraSwiper from "./childComps/PraSwiper.vue"
	import PracticeData from "./childComps/PracticeData.vue"
	import PracticeList from "./childComps/PracticeList.vue"
	export default {
		data() {
			return {
				pralist: [{
					name: '工程类',
					id: 1002,
				}, {
					name: '咨询类',
					id: 1000,
				}, {
					name: '经济类',
					id: 1626,
				}],
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				recomlist: [],
				navlist: [],
				bkzllist: [],
			}
		},
		onLoad() {
			this.getDramSult(1002)
		},
		methods: {
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				this.getDramSult(this.pralist[this.current].id)
			},
			async getDramSult(id) {
				let params = {
					cmd: 'nEdu_list_proc_second',
					para: {
						pageindex: 1,
						pagesize: 100,
						colid: id,
					}
				}
				const res = await this.$u.api.getDramSult(params)
				for (var value of res.Data.Datas1.values()) {
					value.wjlx = this.baseUrl + value.wjlx					
				}
				this.recomlist = this.sliceArray(res.Data.Datas1, 6)
				for (var value of res.Data.Data.values()) { 
					value.logo = this.baseUrl + value.logo
					value.name = value.name.replace(/[0-9]+/g, "")
					
				}
				this.navlist = this.sliceArray(res.Data.Data, 4)
				this.bkzllist = res.Data.Datas2
				for (var value of this.bkzllist.values()) {
					value.img = this.baseUrl + value.img
				}
				console.log(this.recomlist)
			},
			sliceArray(array, size) {
				var result = [];
				for (var x = 0; x < Math.ceil(array.length / size); x++) {
					var start = x * size;
					var end = start + size;
					result.push(array.slice(start, end));
				}
				return result;
			},

			scancode() {
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);

					}
				});
			},
			goSearch(){
				uni.navigateTo({
					url:"/pages/HomeLnner/search/search"
				})
			},
			goDetail(item){
				this.$u.route('/pages/HomeLnner/practice/examination-detail/examination-detail', {
					id: item.id
				});
			}
		},
		components: {
			"home-notice": HomeNotice,
			"pra-swiper": PraSwiper,
			"practice-data": PracticeData,
			"practice-list": PracticeList
		}
	}
</script>

<style scoped lang="scss">
	.navbar_wap {
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: 0 30rpx;

		.navbar-right {
			.search_logo {
				margin-right: 30rpx;
			}
		}
	}

	.services_box {
		padding: 0 30rpx;

		.atlas_img {
			width: 100%;
			padding: 20rpx 0;

			image {
				width: 100%;
				height: 230rpx;
				border-radius: 10rpx;
			}
		}
	}

	.pra_list_box {
		display: flex;
		justify-content: space-between;
		height: 148rpx;
		margin-bottom: 44rpx;
		padding: 0 30rpx;

		image {
			width: 340rpx;
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - 92rpx);
		width: 100%;
	}

	/* #ifndef H5 */
	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - 184rpx);
		width: 100%;
	}

	/* #endif  */
	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>
